<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Banner_model extends CI_Model
{
	function __construct()
    {
        parent::__construct();
	}
	
	function getAllBanner($num,$offset)
	{
		$this->db->where('bl_active !=', -1);
		$this->db->order_by('dt_create','DESC');
		return $this->db->get('banner',$num,$offset)->result();
	}
	
	function get_num_banner()
	{
		$this->db->where('bl_active !=', -1);
		return $this->db->get('banner')->num_rows();          
	}
	
	function delBanner($id)
	{
		$data['bl_active'] = -1 ;
		$data['dt_create'] = date("Y-m-d H:i:s") ;
		$this->db->where('banner_id',$id);
		if($this->db->update('banner', $data)){
		  	return true;
		}else{
		  	return false;
		}
	}
	
	function remove()
	{
		$date = new DateTime();
		$date->modify('-3 month');
		$date_del = $date->format('Y-m-d H:i:s');
		
		$this->db->where('bl_active', -1);
		$this->db->where('dt_create <', $date_del);
		if($this->db->delete('banner')){
		  	return true;
		}else{
		  	return false;
		}
	}
	
	function saveBanner($banner_id,$data)
	{
        if($banner_id != 0){
            $this->db->where('banner_id',$banner_id);
            return $this->db->update('banner',$data);
        }else{
            if($this->db->insert('banner',$data)){
                  return $this->db->insert_id();
            }else{
                  return false;
            }
        }          
	}
    
	function getBannerByID($banner_id=0)
	{
		 $this->db->where('banner_id',$banner_id);
		 return $this->db->get('banner')->row();
	}
	
	/*function get_list_country()
	{
		 $this->db->order_by('lb_country','ASC');
		 return $this->db->get('fm_country')->result();
	}*/
	
    function getAllBannerType()
	{
        return $this->db->get('banner_type')->result();
    }
}
